import os
 
from fastmcp import FastMCP
 
CURRENT_PATH = os.getcwd()
 
mcp = FastMCP(name="StockMCPServer")
 
 
@mcp.tool()
def get_stock_info(code: str) -> str:
    """
    工具：根据股票代码获取股票信息
    :param code:
    :return:
    """
    if code == "09988":
        return f"阿里巴巴-W，港股，股票代码为{code}"
    elif code == "00700":
        return f"腾讯控股，港股，股票代码为{code}"
    else:
        return f"未找到股票代码{code}对应的股票信息"

 
@mcp.tool()
def get_stock_price(code: str) -> float:
    """
    工具：根据股票代码获取股票价格
    :param code:
    :return:
    """
    stock_price_dict = {
        "09988": 111.6,
        "00700": 500.5
    }
    return stock_price_dict.get(code, 0.0)
 
 
@mcp.resource("config://app-version")
def get_app_version() -> str:
    """
    资源：返回应用版本
    :return:
    """
    app_version = "v1.0.0"
    return app_version
 
 
@mcp.resource("db://stocks/{code}/name")
async def get_stock_name(code: str) -> str:
    """
    资源：根据股票代码获取股票名称
    :param code:
    :return:
    """
    stock_name_dict = {
        "09988": "阿里巴巴-W",
        "00700": "腾讯控股"
    }
    return stock_name_dict.get(code, "未知股票")
 
 
@mcp.resource("data://stock-codes")
def get_stock_codes() -> list[str]:
    """
    资源：获取所有股票代码列表
    :return:
    """
    stock_code_list = ["09988", "00700"]
    return stock_code_list
 
 
@mcp.prompt
def introduce_stock(code: str) -> str:
    """
    提示：根据股票代码介绍股票信息
    :param code:
    :return:
    """
    prompt = f"你能帮忙介绍一下股票代码为{code}的详细信息吗？"
    return prompt
 
 
if __name__ == "__main__":
    mcp.run(transport="sse", host="0.0.0.0", port=8090)
 